# CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(modbus_tool VERSION 1.0.0 LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 设置编译选项
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-g -O0 -Wall -Wextra -Wpedantic -Werror -Wunused-parameter)
else()
    add_compile_options(-O2 -Wall -Wextra)
endif()

# 查找线程库
find_package(Threads REQUIRED)

# 主库
add_library(modbus_rtu
    src/modbus_base.cpp
    src/serial_interface.cpp
    src/modbus_tool.cpp
)

target_include_directories(modbus_rtu PUBLIC include)


# 创建可执行文件
add_executable(modbus_demo example/main.cpp)

# 链接库
target_link_libraries(modbus_demo PRIVATE Threads::Threads modbus_rtu)

# 安装规则
install(TARGETS modbus_demo
    RUNTIME DESTINATION bin
)

# 可选：打包
# set(CPACK_PROJECT_NAME ${PROJECT_NAME})
# set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
# include(CPack)
